<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Static variable</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Static_variable"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Static_variable rootpage-Static_variable skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Static variable</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">See also: <a href="Static_(keyword)" title="Static (keyword)">Static (keyword)</a></div>
<p>In <a href="Computer_programming" title="Computer programming">computer programming</a>, a <b>static variable</b> is a <a href="Variable_(programming)" class="mw-redirect" title="Variable (programming)">variable</a> that has been <a href="Memory_allocation" class="mw-redirect" title="Memory allocation">allocated</a> "statically", meaning that its <a href="Variable_lifetime" class="mw-redirect" title="Variable lifetime">lifetime</a> (or "extent") is the entire run of the program. This is in contrast to shorter-lived <a href="Automatic_variable" title="Automatic variable">automatic variables</a>, whose storage is <a href="Stack_allocation" class="mw-redirect" title="Stack allocation">stack allocated</a> and deallocated on the <a href="Call_stack" title="Call stack">call stack</a>; and in contrast to <a href="Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">dynamically allocated</a> objects, whose storage is allocated and deallocated in <a href="Heap_memory" class="mw-redirect" title="Heap memory">heap memory</a>.
</p><p><a href="Variable_lifetime" class="mw-redirect" title="Variable lifetime">Variable lifetime</a> is contrasted with <a href="Scope_(computer_science)" title="Scope (computer science)">scope</a> (where a variable can be used): "global" and "local" refer to scope, not lifetime, but scope often implies lifetime. In many languages, <a href="Global_variable" title="Global variable">global variables</a> are always static, but in some languages they are dynamic, while <a href="Local_variable" title="Local variable">local variables</a> are generally automatic, but may be static.
</p><p>In general, <b><style data-mw-deduplicate="TemplateStyles:r1238216509">
/* start https://en.wikipedia.org/ */
.mw-parser-output .vanchor>:target~.vanchor-text{background-color:#b1d2ff}@media screen{html.skin-theme-clientpref-night .mw-parser-output .vanchor>:target~.vanchor-text{background-color:#0f4dc9}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .vanchor>:target~.vanchor-text{background-color:#0f4dc9}}
/* end https://en.wikipedia.org/ */
</style><span class="vanchor"><span class="vanchor-text">static memory allocation</span></span></b> is the allocation of memory at <a href="Compile_time" title="Compile time">compile time</a>, before the associated program is executed, unlike <a href="Dynamic_memory_allocation" class="mw-redirect" title="Dynamic memory allocation">dynamic memory allocation</a> or <a href="Automatic_memory_allocation" class="mw-redirect" title="Automatic memory allocation">automatic memory allocation</a> where memory is allocated as required at <a href="Run_time_(program_lifecycle_phase)" class="mw-redirect" title="Run time (program lifecycle phase)">run time</a>.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>Static variables date at least to <a href="ALGOL_60" title="ALGOL 60">ALGOL 60</a> (1960), where they are known as <i><b>own</b> variables</i>:
</p>
<style data-mw-deduplicate="TemplateStyles:r1244412712">
/* start https://en.wikipedia.org/ */
.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}
/* end https://en.wikipedia.org/ */
</style><blockquote class="templatequote"><p>A declaration may be marked with the additional declarator <b>own.</b> This has the following effect: upon a re-entry into the block, the values of <b>own</b> quantities will be unchanged from their values at the last exit, while the values of declared variables that are not marked with <b>own</b> is undefined.
</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— Revised report on ALGOL 60, section "5. Declarations", p. 14</p></div>
<p>This definition is subtly different from a static variable: it only specifies behavior, and hence lifetime, not storage: an own variable can be allocated when a function is first called, for instance, rather than at program load time.
</p><p>The use of the word <i>static</i> to refer to these variables dates at least to <a href="BCPL" title="BCPL">BCPL</a> (1966), and has been popularized by the <a href="C_programming_language" class="mw-redirect" title="C programming language">C programming language</a>, which was heavily influenced by BCPL. The BCPL definition reads:
</p>
<blockquote class="templatequote"><p>(1) Static data items:<br>Those data items whose extents lasts as long as the program execution time; such data items have manifest constant Lvalues. Every static data item must have been declared either in a function or routine definition, in a global declaration or as a label set by colon.
</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— The BCPL Reference Manual, 7.2 Space Allocation and Extent of Data Items</p></div>
<p>Note that BCPL defined a "dynamic data item" for what is now called an <i>automatic</i> variable (local, stack-allocated), not for heap-allocated objects, which is the current use of the term <i>dynamic allocation</i>.
</p><p>The <a href="Static_(keyword)" title="Static (keyword)"><code>static</code> keyword</a> is used in C and related languages both for static variables and other concepts.
</p>
<div class="mw-heading mw-heading2"><h2 id="Addressing">Addressing</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1305433154">
/* start https://en.wikipedia.org/ */
.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style>
<p>The <a href="Absolute_address" class="mw-redirect" title="Absolute address">absolute address</a> <a href="Addressing_mode" title="Addressing mode">addressing mode</a> can only be used with static variables, because those are the only kinds of variables whose location is known by the compiler at compile time. When the program (<a href="Executable" title="Executable">executable</a> or <a href="Library_(computing)" title="Library (computing)">library</a>) is <a href="Loader_(computing)" title="Loader (computing)">loaded</a> into memory, static variables are stored in the <a href="Data_segment" title="Data segment">data segment</a> of the program's <a href="Address_space_(application_programming)" class="mw-redirect" title="Address space (application programming)">address space</a> (if initialized), or the <a href="BSS_segment" class="mw-redirect" title="BSS segment">BSS segment</a> (if uninitialized), and are stored in corresponding sections of <a href="Object_file" title="Object file">object files</a> prior to loading.
</p>
<div class="mw-heading mw-heading2"><h2 id="Scope">Scope</h2></div>
<div role="note" class="hatnote navigation-not-searchable">See also: <a href="Variable_(computer_science)#Scope_and_extent" title="Variable (computer science)">Variable (computer science) § Scope and extent</a></div>
<p>In terms of <a href="Variable_(computer_science)#Scope_and_extent" title="Variable (computer science)">scope and extent</a>, static variables have extent the entire run of the program, but may have more limited <a href="Scope_(computer_science)" title="Scope (computer science)">scope</a>. A basic distinction is between a <i>static global variable</i>, which has global scope and thus is in context throughout the program, and a <i><a href="Static_local_variable" class="mw-redirect" title="Static local variable">static local variable</a>,</i> which has local scope. A static local variable is different from a local variable as a static local variable is initialized only once no matter how many times the function in which it resides is called and its value is retained and accessible through many calls to the function in which it is declared, e.g. to be used as a count variable. A static variable may also have <a href="Module_scope" class="mw-redirect" title="Module scope">module scope</a> or some variant, such as <a href="Internal_linkage" class="mw-redirect" title="Internal linkage">internal linkage</a> in <a href="C_programming_language" class="mw-redirect" title="C programming language">C</a>, which is a form of file scope or module scope.
</p>
<div class="mw-heading mw-heading3"><h3 id="Example">Example</h3></div>
<p>An example of a static local variable in C:
</p>
<div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span class="cp">#include</span><span class="w"> </span><span class="cpf"><stdio.h></span>
<span class="kt">void</span><span class="w"> </span><span class="nf">Func</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="w"> </span><span class="c1">// |x| is initialized only once across five calls of |Func| and the variable</span>
<span class="w"> </span><span class="c1">// will get incremented five times after these calls. The final value of |x|</span>
<span class="w"> </span><span class="c1">// will be 5.</span>
<span class="w"> </span><span class="n">x</span><span class="o">++</span><span class="p">;</span>
<span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"%d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">x</span><span class="p">);</span><span class="w"> </span><span class="c1">// outputs the value of |x|</span>
<span class="p">}</span>
<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Func</span><span class="p">();</span><span class="w"> </span><span class="c1">// prints 1</span>
<span class="w"> </span><span class="n">Func</span><span class="p">();</span><span class="w"> </span><span class="c1">// prints 2</span>
<span class="w"> </span><span class="n">Func</span><span class="p">();</span><span class="w"> </span><span class="c1">// prints 3</span>
<span class="w"> </span><span class="n">Func</span><span class="p">();</span><span class="w"> </span><span class="c1">// prints 4</span>
<span class="w"> </span><span class="n">Func</span><span class="p">();</span><span class="w"> </span><span class="c1">// prints 5</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Object-oriented_programming">Object-oriented programming</h2></div>
<p>In <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a>, there is also the concept of a <i><a href="Static_member_variable" class="mw-redirect" title="Static member variable">static member variable</a></i>, which is a "<a href="Class_variable" title="Class variable">class variable</a>" of a statically defined class, i.e., a <a href="Member_variable" title="Member variable">member variable</a> of a given class which is shared across all <a href="Class_instance" class="mw-redirect" title="Class instance">instances</a> (objects), and is accessible as a member variable of these objects. A class variable of a dynamically defined class, in languages where classes can be defined at run time, is allocated when the class is defined and is not static.
</p><p>Object constants known at compile-time, such as <a href="String_literal" title="String literal">string literals</a>, are usually allocated statically. In object-oriented programming, the <a href="Virtual_method_table" title="Virtual method table">virtual method tables</a> of classes are usually allocated statically. A statically defined value can also be <a href="Global_variable" title="Global variable">global</a> in its scope ensuring the same <a href="Immutable_object" title="Immutable object">immutable</a> value is used throughout a run for consistency.
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Constant_(computer_programming)" title="Constant (computer programming)">Constant (computer programming)</a></li>
<li><a href="Global_variable" title="Global variable">Global variable</a></li>
<li><a href="Static_method" class="mw-redirect" title="Static method">Static method</a></li>
<li><a href="Thread-local_storage" title="Thread-local storage">Thread-local storage</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist reflist-columns references-column-width reflist-columns-2">
<ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFJack_Rons" class="citation web cs1">Jack Rons. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20100611071852/http://www.merithub.com/q/58-static-memory-allocation-dynamic-memory-allocation.aspx">"What is static memory allocation and dynamic memory allocation?"</a>. MeritHub [An Institute of Career Development]. Archived from <a rel="nofollow" class="external text" href="http://www.merithub.com/q/58-static-memory-allocation-dynamic-memory-allocation.aspx">the original</a> on June 11, 2010<span class="reference-accessdate">. Retrieved <span class="nowrap">2011-06-16</span></span>. <q>The compiler allocates required memory space for a declared variable. By using the addressof operator, the reserved address is obtained and this address may be assigned to a pointer variable. Since most of the declared variables have static memory, this way of assigning pointer value to a pointer variable is known as static memory allocation. Memory is assigned during compilation time.</q></cite></span>
</li>
</ol></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239549316">
/* start https://en.wikipedia.org/ */
.mw-parser-output .refbegin{margin-bottom:0.5em}.mw-parser-output .refbegin-hanging-indents>ul{margin-left:0}.mw-parser-output .refbegin-hanging-indents>ul>li{margin-left:0;padding-left:3.2em;text-indent:-3.2em}.mw-parser-output .refbegin-hanging-indents ul,.mw-parser-output .refbegin-hanging-indents ul li{list-style:none}@media(max-width:720px){.mw-parser-output .refbegin-hanging-indents>ul>li{padding-left:1.6em;text-indent:-1.6em}}.mw-parser-output .refbegin-columns{margin-top:0.3em}.mw-parser-output .refbegin-columns ul{margin-top:0}.mw-parser-output .refbegin-columns li{page-break-inside:avoid;break-inside:avoid-column}@media screen{.mw-parser-output .refbegin{font-size:90%}}
/* end https://en.wikipedia.org/ */
</style><div class="refbegin" style="">
<ul><li><cite id="CITEREFKernighanRitchie1988" class="citation book cs1"><a href="Brian_Kernighan" title="Brian Kernighan">Kernighan, Brian W.</a>; <a href="Dennis_Ritchie" title="Dennis Ritchie">Ritchie, Dennis M.</a> (1988). <span class="id-lock-registration" title="Free registration required"><a rel="nofollow" class="external text" href="https://archive.org/details/cprogramminglang00bria"><i>The C Programming Language</i></a></span> (2nd ed.). Upper Saddle River, NJ: Prentice Hall PTR. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-13-110362-8</bdi>.</cite></li>
<li><i><a href="The_C%2B%2B_Programming_Language" title="The C++ Programming Language">The C++ Programming Language</a></i> (special edition) by <a href="Bjarne_Stroustrup" title="Bjarne Stroustrup">Bjarne Stroustrup</a> (Addison Wesley, 2000; <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>0-201-70073-5</bdi>)</li></ul>
</div>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}
/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}
/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Memory_management1048" style="padding:3px"><table class="nowraplinks hlist mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */
.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div id="Memory_management1048" style="font-size:114%;margin:0 4em"><a href="Memory_management" title="Memory management">Memory management</a></div></th></tr><tr><td class="navbox-abovebelow" colspan="2"><div>
<ul><li><a href="Memory_management_(operating_systems)" title="Memory management (operating systems)">Memory management as a function of an operating system</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Hardware</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Memory_management_unit" title="Memory management unit">Memory management unit</a> (MMU)</li>
<li><a href="Translation_lookaside_buffer" title="Translation lookaside buffer">Translation lookaside buffer</a> (TLB)</li>
<li><a href="Input%E2%80%93output_memory_management_unit" title="Input–output memory management unit">Input–output memory management unit</a> (IOMMU)</li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Virtual_memory" title="Virtual memory">Virtual memory</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Demand_paging" title="Demand paging">Demand paging</a></li>
<li><a href="Memory_paging" title="Memory paging">Memory paging</a></li>
<li><a href="Page_table" title="Page table">Page table</a></li>
<li><a href="Virtual_memory_compression" title="Virtual memory compression">Virtual memory compression</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Memory_segmentation" title="Memory segmentation">Segmentation</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Protected_mode" title="Protected mode">Protected mode</a></li>
<li><a href="Real_mode" title="Real mode">Real mode</a></li>
<li><a href="Virtual_8086_mode" title="Virtual 8086 mode">Virtual 8086 mode</a></li>
<li><a href="X86_memory_segmentation" title="X86 memory segmentation">x86 memory segmentation</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Memory_allocator" class="mw-redirect" title="Memory allocator">Allocator</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Dlmalloc" class="mw-redirect" title="Dlmalloc">dlmalloc</a></li>
<li><a href="Hoard_memory_allocator" title="Hoard memory allocator">Hoard</a></li>
<li><a href="Jemalloc" class="mw-redirect" title="Jemalloc">jemalloc</a></li>
<li><a href="Libumem" title="Libumem">libumem</a></li>
<li><a href="Mimalloc" title="Mimalloc">mimalloc</a></li>
<li><a href="Ptmalloc" class="mw-redirect" title="Ptmalloc">ptmalloc</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Manual_memory_management" title="Manual memory management">Manual</a> means</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul>
<li><a href="C_dynamic_memory_allocation" title="C dynamic memory allocation">C dynamic memory allocation</a></li>
<li><a href="New_and_delete_(C%2B%2B)" title="New and delete (C++)">new and delete (C++)</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Garbage_collection_(computer_science)" title="Garbage collection (computer science)">Garbage<br>collection</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Automatic_Reference_Counting" title="Automatic Reference Counting">Automatic Reference Counting</a></li>
<li><a href="Boehm_garbage_collector" title="Boehm garbage collector">Boehm garbage collector</a></li>
<li><a href="Cheney's_algorithm" title="Cheney's algorithm">Cheney's algorithm</a></li>
<li><a href="Concurrent_mark_sweep_collector" title="Concurrent mark sweep collector">Concurrent mark sweep collector</a></li>
<li><a href="Finalizer" title="Finalizer">Finalizer</a></li>
<li><a href="Garbage_(computer_science)" title="Garbage (computer science)">Garbage</a></li>
<li><a href="Garbage-first_collector" title="Garbage-first collector">Garbage-first collector</a></li>
<li><a href="Mark%E2%80%93compact_algorithm" title="Mark–compact algorithm">Mark–compact algorithm</a></li>
<li><a href="Reference_counting" title="Reference counting">Reference counting</a></li>
<li><a href="Tracing_garbage_collection" title="Tracing garbage collection">Tracing garbage collection</a></li>
<li><a href="Weak_reference" title="Weak reference">Strong reference</a></li>
<li><a href="Weak_reference" title="Weak reference">Weak reference</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Memory_safety" title="Memory safety">Safety</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Buffer_overflow" title="Buffer overflow">Buffer overflow</a></li>
<li><a href="Buffer_over-read" title="Buffer over-read">Buffer over-read</a></li>
<li><a href="Dangling_pointer" title="Dangling pointer">Dangling pointer</a></li>
<li><a href="Stack_overflow" title="Stack overflow">Stack overflow</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Issues</th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Fragmentation_(computing)" title="Fragmentation (computing)">Fragmentation</a></li>
<li><a href="Memory_leak" title="Memory leak">Memory leak</a></li>
<li><a href="Unreachable_memory" title="Unreachable memory">Unreachable memory</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Other</th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Automatic_variable" title="Automatic variable">Automatic variable</a></li>
<li><a href="International_Symposium_on_Memory_Management" title="International Symposium on Memory Management">International Symposium on Memory Management</a></li>
<li><a href="Region-based_memory_management" title="Region-based memory management">Region-based memory management</a></li>
<li><a href="Memory_pool" title="Memory pool">Memory pool</a></li></ul>
</div></td></tr><tr><td class="navbox-abovebelow" colspan="2"><div>
<ul><li><span class="noviewer" typeof="mw:File"><span title="Category"></span></span> Memory management</li>
<li><span class="noviewer" typeof="mw:File"><span title="Category"></span></span> Virtual memory</li>
<li><span class="noviewer" typeof="mw:File"><span title="Category"></span></span> Automatic memory management</li>
<li><span class="noviewer" typeof="mw:File"><span title="Category"></span></span> Memory management algorithms</li>
<li><span class="noviewer" typeof="mw:File"><span title="Category"></span></span> Memory management software</li></ul>
</div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-01-24" href="https://en.wikipedia.org/wiki/?title=Static_variable&oldid=1271457617">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>